#pragma once
#include <memory>
#include <queue>
#include <mutex>
#include "boost/asio.hpp"
#include "MsgNode.h"

const int MAX_LENGTH = 1024;




using boost::asio::ip::tcp;

class Server;


class Session: public std::enable_shared_from_this<Session>
{
public:
    //io_context用来初始化socket_
    Session(boost::asio::io_context& io_context,Server *server);
    ~Session();
    void Start();
    tcp::socket& GetSocket()
    {
        return socket_;
    }

    std::string& GetUuid()
    {
        return uuid_;
    }
    void Send(char *msg,int max_length);
private:
    //用于回调的函数，用于处理读取来自客户端的数据
    void HandleRead(const boost::system::error_code &ec, std::size_t bytes_transferred,std::shared_ptr<Session> session);
    //用于回调的函数，用于处理写入数据到客户端
    void HandleWrite(const boost::system::error_code &ec,std::shared_ptr<Session> session);
private:

    tcp::socket socket_;

    char _data[MAX_LENGTH];
    Server *server_;
    std::string uuid_;
    std::queue<std::shared_ptr<MsgNode>> _send_queue;
    std::mutex _send_lock;


};